<template>
	<view class="safety" :style="{paddingTop: paddingHeight + 'px'}">
		<nav-bar title="注销账号"></nav-bar>
		<view class="container">
			<u-image width="132rpx" height="132rpx" :showMenuByLongpress="false"
				src="http://oss.antaimedical.com/images/static/2024/06/666a5d71eb14d0f049f44d0dzLbneKYFW0kt589c345374b2007f538d1287127a5aae.png"
				:lazy-load="true"></u-image>
			<view class="l-title">将“{{ userInfo.name ? userInfo.name : '' }}”账号注销</view>
			<view class="l-tips">注销账号将会丢失此账号的所有信息内容，请谨慎操作！</view>
		</view>
		<view class="logout large_button" @click="logoutModal = true">注销账号</view>
		<u-modal :show="logoutModal" @close="logoutModal = false" @cancel="logoutModal = false"
			@confirm="Masklogouttrue" confirmText="确认注销" cancelText="我再想想" showCancelButton cancelColor="#000000"
			confirmColor="#545DDE">
			<view class="tips">
				是否确认注销账号?
			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		logoff
	} from '@/api/index.js'
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				paddingHeight: uni.getStorageSync('navbarHeight'),
				userId: uni.getStorageSync('userId'),
				logoutModal: false
			};
		},
		computed: {
			...mapState({
				ble: state => state.ble, // 实时蓝牙全局状态
				userInfo: state => state.userInfo
			})
		},
		methods: {
			// 确定注销
			async Masklogouttrue() {
				let params = {
					userId: this.userId
				}
				try {
					const res = await logoff(params)
					if (res.code == 200) {
						wx.closeBluetoothAdapter();
						this.$store.commit('changeIsOpenBleAdapter', false)
						this.$store.commit('resetDeviceInfo')
						this.$store.commit('resetUserInfo')
						this.$store.commit('reset')
                        uni.removeStorageSync('userId');
                        uni.removeStorageSync('token');
                        uni.removeStorageSync('app-userInfo');
                        uni.removeStorageSync('app-deviceInfo');
					}
					// uni.removeStorageSync('userId');
					// uni.removeStorageSync('token');
					uni.reLaunch({
						url: '/pagesB/login/index' //这里跳转到登录页，要求用户重新登录
					});
				} catch (e) {
					//TODO handle the exception
				}
			}
		}
	};
</script>
<style lang="scss">
	page {
		background-color: #FAFAFA;
		min-height: 100%;
	}
</style>
<style lang="scss" scoped>
	.container {
		margin-top: 90rpx;
		padding: 0 148rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		color: #333333;

		.l-title {
			margin: 32rpx 0 48rpx 0;
			font-weight: 500;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
		}

		.l-tips {
			font-size: 32rpx;

		}
	}

	.tips {
		padding: 14rpx 0 66rpx;
		font-weight: 500;
		font-size: 32rpx;
		color: #353535;
		font-family: PingFangSC-Medium, PingFang SC;
	}


	.logout {
		position: fixed;
		bottom: 144rpx;
		left: 50%;
		transform: translateX(-50%);
	}
</style>